package ee.az.tetris;

import ee.az.tetris.event.Event;
import ee.az.tetris.worker.Worker;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Artur Zinatullin (artur.zinatullin@gmail.com) 2010
 */
public class Dispatcher {
	
	private Map<Class<? extends Event>, Worker> workers;
	
	public Dispatcher() {
		workers = new HashMap<Class<? extends Event>, Worker>();
	}
	
	public void dispatch(Event event) {
		Worker worker = workers.get(event.getClass());
		if (worker != null) {
			worker.work(event);
		} else {
			throw new RuntimeException("No worker for event " + event);
		}
	}
	
	public void put(Class<? extends Event> event, Worker worker) {
		workers.put(event, worker);
	}
}
